package com.kong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kong.entity.SysUser;
import com.kong.mapper.SysUserMapper;
import com.kong.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kong.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2022-09-06
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private  SysUserMapper userMapper;

    @Override
    public PageUtil queryUser(String key , Integer page) {
        Page<SysUser> userPage = new Page<>(page,PageUtil.SIZE);
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(key),"user_name",key)
                .or().like(StringUtils.isNotBlank(key),"nick_name",key);
        Page<SysUser> resultPage = this.userMapper.selectPage(userPage,queryWrapper);
        PageUtil pageUtil = new PageUtil();
        pageUtil.setData(resultPage.getRecords());//分页数据
        pageUtil.setPage(page);//当前页码
        pageUtil.setTotal(resultPage.getTotal());//总记录数
        pageUtil.setPages(resultPage.getPages());//总页码数
        return  pageUtil;
    }
}
